﻿using B.S.BaseData.ErrorCode;
using B.S.BaseData.ErrorCode.ErrorCodes;
using B.S.BaseData.WriteAPI.Utils;
using B.S.DataBase.EFCoreServiers.Dtos;
using B.S.DataBase.EFCoreServiers.IServices.Meetings;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.WriteAPI.Controllers
{
    /// <summary>
    /// 审批管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    [ApiExplorerSettings(GroupName = "MeetingApproval")]
    public class MeetingApprovalController : ControllerBase
    {
        private readonly IMeetingApprovalServices services;
        private readonly ILogger<MeetingApprovalController> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        public MeetingApprovalController(
            IMeetingApprovalServices services,
            ILogger<MeetingApprovalController> logger)
        {
            this.services = services;
            _logger = logger;
        }

        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="processDto"></param>
        /// <returns></returns>
        [HttpPost]
        [LogOperation("会议审批管理", "审批", "处理会议预约审批")]
        public async Task<ApiResult> ApprovalProcess(MeetingApprovalProcessDto processDto)
        {
            try
            {
                var res = await services.ApprovalProcess(processDto);
                return res;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "审批处理出错");
                return ApiResult.Fail("审批处理出错", StatusCodeEnum.Exception);
            }
        }
        /// <summary>
        /// 重新提交 会议预约申请
        /// </summary>
        /// <param name="MeetingReservationId"></param>
        /// <returns></returns>
        [HttpPost]
        [LogOperation("会议审批管理", "重新提交", "重新提交会议预约申请")]
        public async Task<ApiResult> ApprovalResubmit(int MeetingReservationId)
        {
            try
            {
                var res = await services.ApprovalResubmit(MeetingReservationId);
                return res;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "重新提交出错");
                return ApiResult.Fail("重新提交出错", StatusCodeEnum.Exception);
            }
        }

    }
}
